<template>
    <transition name="fade">
        <div class="dialog-wrapper" v-if="isShow">
            <div class="dialog-mask" @click="handleMaskCancel" v-show="isMaskLayer"></div>
            <div class="dialog-content">
                <slot/>
            </div>
        </div>
    </transition>
</template>

<script>
    export default {
        name: "my-dialog",
        data() {
            return {
                isShow: this.value
            }
        },
        props: {
            // 是否显示弹层
            value: {
                default: false,
                type: Boolean
            },
            // 是否显示遮罩层
            isMaskLayer: {
                default: false,
                type: Boolean
            },
            // 点击遮罩层关闭
            maskHide: {
                default: false,
                type: Boolean
            }
        },
        watch: {
            value(newValue) {
                this.isShow = newValue
                window.console.log(666666)

            }
        },
        methods: {
            handleMaskCancel() {
               this.maskHide && this.$emit('input', false)
            }
        }
    }
</script>

<style lang="less" scoped>
    .dialog-wrapper {
        display: flex;
        justify-content: center;
        align-items: center;
        animation-duration: 100ms;
        z-index: 100;
        .dialog-mask {
            background: rgba(0, 0, 0, 0.5);
            z-index: 4999;
        }
        .dialog-content {
            z-index: 5000;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translateY(-50%) translateX(-50%);
            max-width: 7.5rem;
        }
    }

    .dialog-wrapper, .dialog-mask {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }
</style>
